package common;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;

public class BaseUtils
{

    public static String getUUID()
    {
        return java.util.UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static String getUUIDAndFileNameByBase64(String name)
    {
        return encodeForBase64(String.format("%s-%s", name, getUUID()));
    }

    // 将字符串 Base64 编码
    public static String encodeForBase64(String str)
    {
        return Base64.encodeBase64String(str.getBytes());
    }

    // 将字符串 Base64 解码
    public static String decodeForBase64(String str)
    {
        return new String(Base64.decodeBase64(str.getBytes()));
    }

    // 将字符串 MD5 加密
    public static String encryptForMD5Hex(String str)
    {
        return DigestUtils.md5Hex(str);
    }
    public static String encryptForMD5(String str)
    {
        return DigestUtils.md5Hex(str);
    }

    // 将字符串 SHA 加密
    public static String encryptForSHA(String str)
    {
        return DigestUtils.sha1Hex(str);
    }

    public static void main(String[] args)
    {
        String str="oaisdfahsdfasdfasd=121232jsdfAk=sdfasdfasdfasdfasdfasdfasdfasdfasdfasdf";
        String str2=encryptForMD5(str);
        System.out.println(str2);
        System.out.println(encryptForSHA(str));
        System.out.println(getUUIDAndFileNameByBase64(str));
        System.out.println(encryptForMD5(getUUIDAndFileNameByBase64(str)));
    }
}
